/**
 * 
 */
package org.gas.barapraja.proc;

import java.util.ArrayList;
import java.util.List;

import org.gas.barapraja.db.entity.Message;

/**
 * @author gilang
 *
 */
public class TemporaryMsgStore{
	
	private static List<Message> messages=new ArrayList<Message>();
	
	private TemporaryMsgStore(){}
	
	private static MsgStore msgStore;
	
	public static MsgStore getInstance(){
		if(msgStore==null)
			msgStore=new MsgStore(){
			@Override
			public synchronized void addMsg(Message message) {
				if(!messages.contains(message))
					messages.add(message);
			}

			@Override
			public synchronized void removeMsg(Message message) {
				if(messages.contains(message))
					messages.remove(message);
			}

			@Override
			public synchronized Message getMsg(int index) {
				return messages.get(index);
			}

			@Override
			public synchronized int count() {
				return messages.size();
			}
		};
		return msgStore;
		
	}

	

}
